package cn.ainit.bj.bjxt;

import cn.ainit.common.ReturnObject;
import cn.ainit.sys.ds.store.StoreService;
import cn.ainit.sys.framework.FrameworkService;
import cn.ainit.sys.framework.save.CommonSaveService;
import cn.ainit.sys.framework.save.ReceiveObj;
import cn.ainit.sys.framework.save.ReceiveZM;
import cn.ainit.sys.menu.SessionCont;
import cn.ainit.sys.query.datastore.DataStore;
import cn.ainit.sys.query.entity.QueryJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("bjTopicsServiceImpl")
public class BJTopicsServiceImpl implements BJTopicsService {
	
	private BJTopicsDao bjTopicsDao;
	private FrameworkService frameworkService;
	private CommonSaveService commonSaveService;
	private StoreService storeService;

	@Resource
	public void setStoreService(StoreService storeService) {
		this.storeService = storeService;
	}

	@Resource
	public void setBjTopicsDao(BJTopicsDao bjTopicsDao) {
		this.bjTopicsDao = bjTopicsDao;
	}

	@Resource
	public void setFrameworkService(FrameworkService frameworkService) {
		this.frameworkService = frameworkService;
	}

	@Resource
	public void setCommonSaveService(CommonSaveService commonSaveService) {
		this.commonSaveService = commonSaveService;
	}

	@Override
	public boolean updateObject(String sqlText, String[] valuesArr,
			String[] whereValue) throws Exception {
		return bjTopicsDao.updateObject(sqlText,valuesArr,whereValue);
	}
	@Override
	public BJTopics getOneBjTopic(String dsId) throws Exception {
		return bjTopicsDao.getOneBjTopic(dsId);
	}
	
	@Override
	public boolean saveTopics(BJTopics bjTopics) throws Exception {
		return bjTopicsDao.saveTopics(bjTopics);
	}
	
	@Override
	public boolean updateTopics(BJTopics bjTopics) throws Exception {
		return bjTopicsDao.updateTopics(bjTopics) ;
	}
	@Override
	public String makeLiXiang(String xtId) throws Exception {
		return bjTopicsDao.makeLiXiang(xtId);
	}
	
	@Override
	public boolean piPeiBookList(String xtId,String hId) throws Exception{
		return bjTopicsDao.piPeiBookList(xtId, hId);
	}

	@Override
	public List<String> getColsByDsId(String dsId) {
		return bjTopicsDao.getColsByDsId(dsId);
	}

	@Override
	public String getUpdateTable(String colName) {
		return bjTopicsDao.getUpdateTable(colName);
	}
	@Override
	public String isbnCIP(String xtId,String manId) throws Exception {
		return bjTopicsDao.isbnCIP(xtId,manId);
	}
	@Override
	public String sanShen(String xtId,String manId) throws Exception {
		return bjTopicsDao.sanShen(xtId,manId);
	}
	@Override
	public String beginPlan(String xtId, String manId) throws Exception {
		return bjTopicsDao.beginPlan(xtId, manId);
	}
	@Override
	public boolean execSql(String sql) throws Exception {
		return bjTopicsDao.execSql(sql);
	}

//	@Override
//	public boolean judgeXtId(String xtId) throws Exception {
//		return bjTopicsDao.judgeXtId(xtId);
//	}
	@Override
	public String xtPlanRight(String xtId, String manId) throws Exception {
		return bjTopicsDao.xtPlanRight(xtId, manId);
	}

	@Override
	public List getzhanghaobymanid(String mb) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getzhanghaobymanid(mb);
	}
	
	@Override
	public List getManInfoByManID(String mb) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getManInfoByManID(mb);
	}

    @Override
    public List getInfobyParty1(String XT_NAME,String PAY_PARTY) {
        return bjTopicsDao.getInfobyParty1(XT_NAME,PAY_PARTY);
    }

    @Override
    public boolean checkExistsNotVerifyDj(String XT_NAME,String PAY_PARTY) {
        return bjTopicsDao.checkExistsNotVerifyDj(XT_NAME,PAY_PARTY);
    }



    @Override
	public List getManAccounts(String man) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getManAccounts(man);
	}
	
	@Override
	public List getXtYinCi(String xtId,String yinCi) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getXtYinCi(xtId,yinCi);
	}
	
	@Override
	public List getBSMoney(String xtId,String manID,String contract_TYPE,String type) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getBSMoney(xtId,manID,contract_TYPE,type);
	}
    @Override
    public List getZZBSMoney(String xtId,String manID) {
        // TODO Auto-generated method stub
        return bjTopicsDao.getZZBSMoney(xtId, manID);
    }
//    @Override
//    public List getZZJTBSMoney(String sinid) {
//        // TODO Auto-generated method stub
//        return bjTopicsDao.getZZJTBSMoney(sinid);
//    }
    @Override
    public List getamount(String PAY_PARTY, String BASIS_ACCOUNT, String TOPIC_SELECTED) {
        // TODO Auto-generated method stub
        return bjTopicsDao.getamount(PAY_PARTY, BASIS_ACCOUNT, TOPIC_SELECTED);
    }

    @Override
    public List get_zzdata(String CWZZ_ID, String PAY_PARTY, String BASIS_ACCOUNT, String TOPIC_SELECTED) {
        // TODO Auto-generated method stub
        return bjTopicsDao.get_zzdata(CWZZ_ID, PAY_PARTY, BASIS_ACCOUNT, TOPIC_SELECTED);
    }

	@Override
	public List getAnyAccount(String mb) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getAnyAccount(mb);
	}

	@Override
	public List getAllMoney(String mb) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getAllMoney(mb);
	}
	
	@Override
	public List getzhanghaobyoid(String mb) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getzhanghaobyoid(mb);
	}

	@Override
	public List<String> getJTBM(List<String> runIds) throws Exception {
		// TODO Auto-generated method stub
		return bjTopicsDao.getJTBM(runIds);
	}

    @Override
    public List<String> getzzJTBM(List<String> runIds) throws Exception {
        // TODO Auto-generated method stub
        return bjTopicsDao.getzzJTBM(runIds);
    }
    @Override
    public List<String> getzzJTBMTWO(List<String> runIds) throws Exception {
        // TODO Auto-generated method stub
        return bjTopicsDao.getzzJTBMTWO(runIds);
    }


    @Override
	public List<String> getJTBMTWO(List<String> runIds) throws Exception {
		// TODO Auto-generated method stub
		return bjTopicsDao.getJTBMTWO(runIds);
	}

	@Override
	public List getDJtypeByc(String xtId, String manID, String contractTYPE) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getDJtypeByc(xtId, manID, contractTYPE);
	}
    @Override
    public List getDJtypeByz(String xtId, String manID, String TYPE_TICKET) {
        // TODO Auto-generated method stub
        return bjTopicsDao.getDJtypeByz(xtId, manID, TYPE_TICKET);
    }


    @Override
	public List getNextYinci(String xtId, String manID, String contractTYPE,String yinci) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getNextYinci(xtId, manID, contractTYPE, yinci);
	}
	@Override
	public List getNextYinciVerify(String xtId, String manID) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getNextYinciVerify(xtId, manID);
	}
	
	@Override
	public List getNowOidMan(String oid) {
		// TODO Auto-generated method stub
		return bjTopicsDao.getNowOidMan(oid);
	}

	@Override
	public List getTrueContra(String xtId, String manID) {
		return bjTopicsDao.getTrueContra(xtId, manID);
	}

	@Override
	public int getBookDelYinci(String xtId,String manID,String yinci,int number) {
		return bjTopicsDao.getBookDelYinci(xtId,manID,yinci,number);
	}
	
	@Override
	public List getXtInfo(String xtId, String yinci) {
		return bjTopicsDao.getXtInfo(xtId, yinci);
	}
	
	@Override
	public List getPubMoney(String XT_PUB_ID) {
		return bjTopicsDao.getPubMoney(XT_PUB_ID);
	}

	@Override
	public List getIsOrSave(String xtId, String manID, String yinci, int number) {
		return bjTopicsDao.getIsOrSave(xtId, manID, yinci, number);
	}

    public double getMarketAmount(String xt_id){
        return bjTopicsDao.getMarketAmount(xt_id);
    }

	@Transactional
	@Override
	public List<ReturnObject> saveAutoCheckAccountInfo(String dsId, String PAY_PARTY, String XT_NAME, String sfct, Object uid, HttpServletRequest request, HttpSession session) throws Exception {
		List<ReturnObject> objs = new ArrayList<>();
		//选题信息
		List xtInfos = getInfobyParty1(XT_NAME,PAY_PARTY);

		if(CollectionUtils.isEmpty(xtInfos)) {
			throw new RuntimeException("获取选题信息发生错误！");
		}
		Map xtInfo = (Map)xtInfos.get(0);
		String BASIS_ACCOUNT = null==xtInfo.get("BASIS_ACCOUNT")?"":xtInfo.get("BASIS_ACCOUNT").toString();
		if(BASIS_ACCOUNT.equals("印数") || BASIS_ACCOUNT.equals("dz_bsjsyj.001")) {
			throw new RuntimeException("该选题属于按印数结算，不能使用自动对账功能请重新选择！");
		}

		DataStore dataStore = frameworkService.getDataStoreById(dsId);

		String sql = frameworkService.formatSql(dsId, dataStore.getSqlText(), uid == null ? "" : uid.toString());
		String finalSql = sql +
				" WHERE ttmp.TOPIC_SELECTED = '"+XT_NAME+"' " +
				"      AND ttmp.PAY_PARTY = '"+PAY_PARTY+"' " +
				"  and to_date(ttmp.ZZDZ_MONTH,'yyyy-MM') <= add_months(sysdate, -2) " +
				" ORDER BY ttmp.ZZDZ_MONTH ASC";

		//拆套计算
		if("1".equals(sfct)) {
			finalSql = finalSql.replace("VV_BJ_ZZDZ", "VV_BJ_ZZDZ_CT");
		}

		QueryJson tmpQJ = frameworkService.queryRowsBySqlPagination(finalSql, 1, 300);
		List list = tmpQJ.getRows() == null ? new ArrayList() : tmpQJ.getRows();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
		Calendar calendar = Calendar.getInstance();
		List result = new ArrayList();
		if(list.size() > 0) {
			Map start = (Map)list.get(0);
			String currMonth = start.get("ZZDZ_MONTH").toString();

			calendar.setTime(format.parse(currMonth));
			calendar.add(Calendar.MONTH, 1);
			String next = format.format(calendar.getTime());
			List subList = new ArrayList();
			for(int i=0;i<list.size();i++) {
				Map map = (Map)list.get(i);
				String month = map.get("ZZDZ_MONTH").toString();
				if(currMonth.equals(month)) {
					subList.add(map);
				} else {
					fillDJInfos(subList);
					objs.add(saveCheckAccountInfo(subList,xtInfo, calculateNUMBER_TOTAL_DELIVERY(PAY_PARTY, BASIS_ACCOUNT, XT_NAME), uid, request, session));
					if(next.equals(month)) {
						subList = new ArrayList();
						subList.add(map);
						currMonth = map.get("ZZDZ_MONTH").toString();
					} else {
						subList = new ArrayList();
						Map temp = new HashMap();
						temp.putAll(map);
						temp.put("DJ_TYPE", "XT");
						temp.put("AMOUNT", "0");
						temp.put("ZZDZ_MONTH", next);
						subList.add(temp);
						temp = new HashMap();
						temp.putAll(map);
						temp.put("DJ_TYPE", "XS");
						temp.put("AMOUNT", "0");
						temp.put("ZZDZ_MONTH", next);
						subList.add(temp);
						temp = new HashMap();
						temp.putAll(map);
						temp.put("DJ_TYPE", "FX");
						temp.put("AMOUNT", "0");
						temp.put("ZZDZ_MONTH", next);
						subList.add(temp);
						currMonth = next;
						i--;
					}
					calendar.setTime(format.parse(currMonth));
					calendar.add(Calendar.MONTH, 1);
					next = format.format(calendar.getTime());
				}
			}
			fillDJInfos(subList);
			objs.add(saveCheckAccountInfo(subList,xtInfo, calculateNUMBER_TOTAL_DELIVERY(PAY_PARTY, BASIS_ACCOUNT, XT_NAME), uid, request, session));
		} else {
			throw new RuntimeException("没有可对账的月份！");
		}

		return objs;
	}

	private String calculateNUMBER_TOTAL_DELIVERY(String PAY_PARTY, String BASIS_ACCOUNT, String XT_NAME) {
		List accounts = getamount(PAY_PARTY,BASIS_ACCOUNT,XT_NAME);
		Map account = CollectionUtils.isEmpty(accounts)?null:(Map)accounts.get(0);
		return null==account?"":account.get("JNUMBER").toString();
	}

	private void fillDJInfos(List list) {
    	List types = new ArrayList(Arrays.asList("XS", "XT", "FX"));
		Map map = (Map)list.get(0);
    	for(int i=0;i<list.size();i++) {
    		types.remove(((Map)list.get(i)).get("DJ_TYPE"));
		}
		for(int i=0;i<types.size();i++) {
			Map temp = new HashMap();
			if(types.get(i).equals("XS")) {
				temp.putAll(map);
				temp.put("DJ_TYPE", "XS");
				temp.put("AMOUNT", "0");
				list.add(temp);
			} else if (types.get(i).equals("XT")) {
				temp.putAll(map);
				temp.put("DJ_TYPE", "XT");
				temp.put("AMOUNT", "0");
				list.add(temp);
			} else if (types.get(i).equals("FX")) {
				temp.putAll(map);
				temp.put("DJ_TYPE", "FX");
				temp.put("AMOUNT", "0");
				list.add(temp);
			}
		}
	}

	private ReturnObject saveCheckAccountInfo(List list, Map xtInfo, String NUMBER_TOTAL_DELIVERY,Object uid, HttpServletRequest request,HttpSession session) throws Exception {
		String TOPIC_SELECTED = null==xtInfo.get("TOPIC_SELECTED")?"":xtInfo.get("TOPIC_SELECTED").toString();
		String PAY_PARTY = null==xtInfo.get("PAY_PARTY")?"":xtInfo.get("PAY_PARTY").toString();
		String AUTHOR = null==xtInfo.get("AUTHOR")?"":xtInfo.get("AUTHOR").toString();
		String BASIS_ACCOUNT = null==xtInfo.get("BASIS_ACCOUNT")?"":xtInfo.get("BASIS_ACCOUNT").toString();
		String TYPE_TICKET = null==xtInfo.get("TYPE_TICKET")?"":xtInfo.get("TYPE_TICKET").toString();
		String ROYALTY_SALE = null==xtInfo.get("ROYALTY_SALE")?"":xtInfo.get("ROYALTY_SALE").toString();
		String PRICE = null==xtInfo.get("PRICE")?"":xtInfo.get("PRICE").toString();
		String PARAMETER_ROYALTY = null==xtInfo.get("PARAMETER_ROYALTY")?"":xtInfo.get("PARAMETER_ROYALTY").toString();
		String TAX_RATE = null==xtInfo.get("TAX_RATE")?"":xtInfo.get("TAX_RATE").toString();
		String DJ_TYPE = null==xtInfo.get("DJ_TYPE")?"":xtInfo.get("DJ_TYPE").toString();
		String BALANCE_PREPAY = null==xtInfo.get("BALANCE_PREPAY")?"":xtInfo.get("BALANCE_PREPAY").toString();

		ReceiveZM receiveZMobj = new ReceiveZM();
		ReceiveObj zmReceiveObj = new ReceiveObj();
		zmReceiveObj.setDiu("0");
		zmReceiveObj.setDsid("ds_zc_authorcheck1");
		Map<String, Object> mapRecord = new HashMap<>();
		mapRecord.put("AUTHOR", AUTHOR);
		mapRecord.put("BALANCE_PREPAY", BALANCE_PREPAY);
		mapRecord.put("BASIS_ACCOUNT", BASIS_ACCOUNT);
		mapRecord.put("CWZZ_ID", "");
		mapRecord.put("DJ_CODE", "");
		mapRecord.put("DJ_TYPE", DJ_TYPE);
//		mapRecord.put("DZ_DATE", new Date().getTime());
		calculateOrderNumber(mapRecord, list,ROYALTY_SALE);
		calculateFormulas(mapRecord, TOPIC_SELECTED, PAY_PARTY, DJ_TYPE,PRICE, ROYALTY_SALE, TYPE_TICKET);
		mapRecord.put("NUMBER_PRINT", "0");
		mapRecord.put("NUMBER_TOTAL_DELIVERY", NUMBER_TOTAL_DELIVERY);
		mapRecord.put("NUMBER_TOTAL_PRINT", "0");
		mapRecord.put("PARAMETER_ROYALTY", PARAMETER_ROYALTY);
		mapRecord.put("PAY_PARTY", PAY_PARTY);
		mapRecord.put("PRICE", PRICE);
		mapRecord.put("ROYALTY_SALE", ROYALTY_SALE);
		mapRecord.put("TAX_RATE", TAX_RATE);
		mapRecord.put("TOPIC_SELECTED", TOPIC_SELECTED);
		mapRecord.put("TYPE_TICKET", TYPE_TICKET);
		zmReceiveObj.setMapRecord(mapRecord);
		receiveZMobj.setZmReceiveObj(zmReceiveObj);

		List<ReceiveObj> receiveObjs = new ArrayList<ReceiveObj>();
		String ZZDZ_MONTH = "";
		if(!CollectionUtils.isEmpty(list)) {
			ReceiveObj obj = null;
			for(int i=0;i<list.size();i++) {
				Map map = (Map)list.get(i);
				ZZDZ_MONTH = map.get("ZZDZ_MONTH").toString();
				mapRecord.put("DZ_DATE", new SimpleDateFormat("yyyy-MM").parse(ZZDZ_MONTH).getTime());
				obj = new ReceiveObj();
				obj.setDiu("0");
				obj.setDsid("ds_zc_authorcheck_item1");
				Map<String, Object> record = new HashMap<>();
				if(ROYALTY_SALE.equals("0") && map.get("DJ_TYPE").toString().equals("FX")) {
					record.put("AMOUNT", 0);
				} else {
					record.put("AMOUNT", map.get("AMOUNT"));
				}
				record.put("CWZZ_ID", map.get("CWZZ_ID"));
				record.put("CWZZ_ITEM_ID", map.get("CWZZ_ITEM_ID"));
				record.put("DATE_VERIFY", map.get("DATE_VERIFY"));
				record.put("DJ_CODE", map.get("DJ_CODE"));
				record.put("DJ_TYPE", map.get("DJ_TYPE"));
				record.put("IS_STOKETIME", map.get("IS_STOKETIME"));
				record.put("I_INFO", map.get("I_INFO"));
				record.put("NUMBER_PRINT", map.get("NUMBER_PRINT"));
				record.put("TOPIC_SELECTED", map.get("TOPIC_SELECTED"));
				record.put("ZZDZ_ISBN", map.get("ZZDZ_ISBN"));
				record.put("ZZDZ_MONTH", map.get("ZZDZ_MONTH"));
				record.put("kk", map.get("kk"));
				obj.setMapRecord(record);
				receiveObjs.add(obj);
			}
			receiveZMobj.setReceiveObjs(receiveObjs);
		}
		ReturnObject obj = commonSaveService.saveCommU(receiveZMobj,session,request);
		obj.setInfo(ZZDZ_MONTH);

		String cwzz_id = obj.getInfob().toString().split("-")[1];
		try {
			storeService.execProcedure(cwzz_id, "ds_zc_authorcheck1", uid.toString(), null == session.getAttribute(SessionCont.STATION_ID) ? "" : session.getAttribute(SessionCont.STATION_ID).toString(), storeService.procedureByDsId("ds_zc_authorcheck1", "zzdz_VERIFY_BUT").getProcedure());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return obj;
	}

	// 计算促销单，退单，销售单数量
	private void calculateOrderNumber(Map<String, Object> mapRecord, List list, String ROYALTY_SALE) {
    	int total = 0;
    	String xs = "0", xt = "0";
    	for(int i=0;i<list.size();i++) {
    		Map map = (Map)list.get(i);
			if(map.get("DJ_TYPE").toString().equals("XS")) {
				xs = map.get("AMOUNT").toString();
			} else if (map.get("DJ_TYPE").toString().equals("XT")) {
				xt = map.get("AMOUNT").toString();
			} else {
				if(ROYALTY_SALE.equals("0")) {
					mapRecord.put("NUMBER_SALE", "0");
				} else {
					mapRecord.put("NUMBER_SALE", map.get("AMOUNT"));
				}
			}
		}
		mapRecord.put("NUMBER_DELIVERY", Integer.parseInt(xs)+Integer.parseInt(xt));
	}

	// 计算税率
	private void calculateFormulas(Map<String, Object> mapRecord, String TOPIC_SELECTED, String PAY_PARTY,
								   String DJ_TYPE, String PRICE, String ROYALTY_SALE, String TYPE_TICKET

	) throws Exception {
    	String NUMBER_DELIVERY = mapRecord.get("NUMBER_DELIVERY").toString();
    	String NUMBER_SALE = mapRecord.get("NUMBER_SALE").toString();
    	float banshui = 0;
		List list = getZZBSMoney(TOPIC_SELECTED,PAY_PARTY);
		//固定版税率
		if(DJ_TYPE.equals("contract.001")) {
			Float jshuTrue = 0f, bsTrue = 0f;
			Double priceTrue = 0d, money = 0d, cx = 0d;
			BigDecimal yfmoney = new BigDecimal(0);
			if(!CollectionUtils.isEmpty(list)) {
				Map map = (Map)list.get(0);
				banshui = Float.parseFloat(map.get("PARAMETER_ROYALTY").toString().split(";")[0]);
				mapRecord.put("PARAMETER_ROYALTY", banshui);
				bsTrue = banshui;
				jshuTrue = Float.parseFloat(NUMBER_DELIVERY);
				priceTrue = new BigDecimal(Double.parseDouble(PRICE)*100).divide(new BigDecimal(100)).doubleValue();
				money = bsTrue * jshuTrue * priceTrue;
				if (ROYALTY_SALE.equals("0")) {
					mapRecord.put("PAY_SHOULD", new BigDecimal(money).setScale(2,BigDecimal.ROUND_HALF_UP));
					BigDecimal reallyMoney = new BigDecimal(money).multiply(new BigDecimal(88.8)).divide(new BigDecimal(100));
					if (TYPE_TICKET.equals("dz_fptype.003")) {
						mapRecord.put("PAY_REAL", reallyMoney.setScale(2,BigDecimal.ROUND_HALF_UP));
					} else {
						mapRecord.put("PAY_REAL", new BigDecimal(money).setScale(2,BigDecimal.ROUND_HALF_UP));
					}
				} else {
					cx = Double.parseDouble(NUMBER_SALE);
					BigDecimal cxmoney = new BigDecimal(cx * priceTrue * 0.5 * bsTrue).setScale(2,BigDecimal.ROUND_HALF_UP);//促销的金额
					yfmoney = new BigDecimal(money).subtract(cxmoney);
					mapRecord.put("PAY_SHOULD", yfmoney.setScale(2,BigDecimal.ROUND_HALF_UP));
					BigDecimal reallyMoney = yfmoney.multiply(new BigDecimal(88.8)).divide(new BigDecimal(100));
					if (TYPE_TICKET.equals("dz_fptype.003")) {
						mapRecord.put("PAY_REAL", reallyMoney.setScale(2,BigDecimal.ROUND_HALF_UP));
					} else {
						mapRecord.put("PAY_REAL", yfmoney.setScale(2,BigDecimal.ROUND_HALF_UP));
					}
				}
			}

			//判断是否促销:1 是；0否
			String str = "";
			if (ROYALTY_SALE.equals("0")) {
				str = "计算公式：" + jshuTrue + " * " + priceTrue + " * " + bsTrue + " = " + new BigDecimal(money).setScale(2,BigDecimal.ROUND_HALF_UP);
			} else {
				str = "计算公式：" + jshuTrue + " * " + priceTrue + " * " + bsTrue + "  - " + cx + " * " + priceTrue + " * "+ bsTrue + " * " + 0.5 + "= " + yfmoney.setScale(2,BigDecimal.ROUND_HALF_UP);
			}
			mapRecord.put("FORMULAS_CALCULATE", str);
		} else if(DJ_TYPE.equals("contract.002")) {//阶梯版税率
			if(!CollectionUtils.isEmpty(list)) {
				Map map = (Map) list.get(0);
				mapRecord.put("PARAMETER_ROYALTY", map.get("PARAMETER_ROYALTY"));
				List<String> runIds = new ArrayList<>();
				runIds.add(NUMBER_DELIVERY);
				runIds.add("ds_zc_authorcheck1");
				runIds.add(map.get("SIN_ID").toString());
				runIds.add(PAY_PARTY);
				runIds.add(TOPIC_SELECTED);
				runIds.add(PRICE);

				List<String> list1 = getzzJTBMTWO(runIds);
				if(!CollectionUtils.isEmpty(list1)) {
					String[] rts = list1.get(0).split("\\^");
					String expStr = rts[0];
					String bsmoney = rts[1];
					String jttax = rts[3];
					BigDecimal reallyMoney = new BigDecimal(bsmoney).multiply(new BigDecimal(88.8)).divide(new BigDecimal(100));
					if (TYPE_TICKET.equals("dz_fptype.003")) {
						mapRecord.put("PAY_REAL", reallyMoney.setScale(2,BigDecimal.ROUND_HALF_UP));
					} else {
						mapRecord.put("PAY_REAL", new BigDecimal(bsmoney).setScale(2,BigDecimal.ROUND_HALF_UP));
					}
					mapRecord.put("PAY_SHOULD", new BigDecimal(bsmoney).setScale(2,BigDecimal.ROUND_HALF_UP));
					mapRecord.put("FORMULAS_CALCULATE", expStr);
					Double cx = 0d;
					BigDecimal yfmoney = new BigDecimal(0);
					//判断是否促销:1 是；0否
					if (ROYALTY_SALE.equals("0")) {
						mapRecord.put("PAY_SHOULD", new BigDecimal(bsmoney).setScale(2,BigDecimal.ROUND_HALF_UP));
						if (TYPE_TICKET.equals("dz_fptype.003")) {
							mapRecord.put("PAY_REAL", reallyMoney.setScale(2,BigDecimal.ROUND_HALF_UP));
						} else {
							mapRecord.put("PAY_REAL", new BigDecimal(bsmoney).setScale(2,BigDecimal.ROUND_HALF_UP));
						}
					} else {
						cx = Double.parseDouble(NUMBER_SALE);//促销数的确认
						//var jttax=str.substring(29, str.indexOf("B"));
						BigDecimal cxmoney = new BigDecimal(cx).multiply(new BigDecimal(PRICE)).multiply(new BigDecimal(0.5)).multiply(new BigDecimal(jttax));//促销的金额
						yfmoney = new BigDecimal(bsmoney).subtract(cxmoney);//促销应付金额
						mapRecord.put("PAY_SHOULD", yfmoney.setScale(2,BigDecimal.ROUND_HALF_UP));
						if (TYPE_TICKET.equals("dz_fptype.003")) {
							mapRecord.put("PAY_REAL", reallyMoney.setScale(2,BigDecimal.ROUND_HALF_UP));
						} else {
							mapRecord.put("PAY_REAL", yfmoney.setScale(2,BigDecimal.ROUND_HALF_UP));
						}
					}
					String str1 = expStr + "\n" + "应付：" + bsmoney + "-(" + cx + " * " + PRICE + " * " + jttax + " * " + 0.5 + ")= " + yfmoney.setScale(2,BigDecimal.ROUND_HALF_UP);
					//判断是否促销:1 是；0否
					if (ROYALTY_SALE.equals("0")) {
						mapRecord.put("FORMULAS_CALCULATE", expStr);
					} else {
						mapRecord.put("FORMULAS_CALCULATE", str1);
					}
				}
			}
		} else if (DJ_TYPE.equals("contract.003")) {
			throw new RuntimeException("版税类型为“固定金额”，不进行对账,请重新选择对账的选题！");
		} else if (DJ_TYPE.equals("contract.008")) {
			throw new RuntimeException("版税类型为“按千字”，不进行对账,请重新选择对账的选题！");
		}
	}

	public static void main(String[] args) {
		String a = "-20", b = "10";
		System.out.println(Integer.parseInt(a)+Integer.parseInt(b));
	}
}
